#include <windows.h> // MultiByteToWideChar, WideCharToMultiByte

extern char *utf8_to_gb2312(char *utf8)
{
	// 有点浪费，对吧。怎么优化呢？
	int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
	wchar_t *wstr = calloc(len + 1, sizeof(wchar_t)); // calloc会设置全0
	char *gb2312 = calloc(len + 1, sizeof(wchar_t /* !!! */));
		// gb2312每个汉字及符号两个字节，设置成和宽字节一样的长度不会超
	
	/* if (!wstr || !gb2312)
	{
		assert_notify(0);
		return 0;
	} */
	
	MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, len);
	len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
	WideCharToMultiByte(CP_ACP, 0, wstr, -1, gb2312, len, NULL, NULL);
	free(wstr);
	return gb2312;
}